import { defineStore } from 'pinia'
import dashboardApi from '@/api/dashboard'

// export const useDashboardStore = defineStore('user', () => {
//     // 获取用户列表
//     const listCard = async (params) => {
//         const res = await dashboardApi.listCard(params)
//         return res.data
//     }
//
//
//     return {
//         listCard
//     }
// })


export const useDashboardStore = defineStore('dashboard', {
    state: () => ({
        cardData: null,
        loading: false
    }),

    actions: {
        async listCard(params) {
            try {
                this.loading = true
                const res = (await dashboardApi.listCard(params)).data
                if (res.success) {
                    this.cardData = res.data.cardVoList
                }
                return res
            } catch (error) {
                console.error('获取仪表盘数据失败:', error)
                return null
            } finally {
                this.loading = false
            }
        }
    }
})